package com.imooc.ecommerce.controller;

import com.imooc.ecommerce.feign.SentinelFeignClient;
import com.imooc.ecommerce.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * OpenFeign集成Sentinel实现熔断降级
 * @author zhangshao
 * @since 2023/12/7 20:40
 */
@Slf4j
@RestController
@RequestMapping("/sentinel-feign")
public class SentinelFeignController {

    @Autowired
    private SentinelFeignClient sentinelFeignClient;

    /**
     * 通过Feign接口去获取结果
     * @param code
     * @return
     */
    @GetMapping("/result-by-feign")
    public CommonResponse<String> getResultByFeign(@RequestParam Integer code){
        log.info("coming in get result by feign :[{}]",code);
        return sentinelFeignClient.getResultByFeign(code);
    }
}
